package com.controller;

import com.entity.Flower;
import com.service.FlowerService;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Data
@RestController
@RequestMapping("/flower")
@CrossOrigin
public class FlowerController {
    @Autowired
    private FlowerService flowerService;

    // 查询所有花
    @GetMapping
    public List<Flower> selectAllFlowers() {
        return flowerService.selectAllFlowers();
    }


    // id 查询一朵花
    @GetMapping("/{id}")
    public Flower selectOneFlowerById(@PathVariable String id) {
        return flowerService.selectOneFlowerById(Integer.parseInt(id));
    }

    // id 删除一朵花
    @DeleteMapping("/{id}")
    public int deleteOneFlowerById(@PathVariable String id) {
        return flowerService.deleteOneFlowerById(Integer.parseInt(id));
    }

    // name 查询一朵花
    @GetMapping(params = "name")
    public List<Flower> selectOneFlowerByName(String name) {
        return flowerService.selectOneFlowerByName(name);
    }


    // 新增一朵花
    @PostMapping
    public int insertOneFlower(@RequestBody Flower flower) {
        return flowerService.insertOneFlower(flower);
    }

    // 修改一朵花
    @PutMapping
    public int updateOneFlower(@RequestBody Flower flower) {
        return flowerService.updateOneFlower(flower);
    }
}
